#include<stdio.h>

int diff(int year)
{
	int digit = 0, i = 0, j = 0, diffnum = 1;
	int digits[4] = {0};
	
	while(year != 0)
	{
		digits[i++] = year % 10;
		year /= 10;
		if (i >= 4)
			break;
	}
		for (i = 0; i < 3; i ++)
		{
			int isdiff = 1;
			for (j = i + 1; j < 4; j ++)
			{
				if (digits[i] != digits[j])
				{
					continue;
				}
				else
				{
					isdiff = 0;
					break;
				}
			} 
			diffnum += isdiff;
		}

	return diffnum;
}

int main()
{
	int year = 0, diffnum = 0, n = 0;
	scanf("%d", &year);
	scanf("%d", &n);
	
	int x;
	for (x = 1; ;x ++) 
	{
		if(n == diff(year + x))
			break;
	}
	
	printf("%d %04d", x, year + x);
	
	return 0;
}
